package com.jaya.budan.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.jaya.budan.R;
import com.jaya.budan.bean.User_Limit;
import com.jaya.budan.bean.XYF_JiLu;
import com.jaya.budan.views.Circle_ImageView;

import java.util.List;

public class Topic_ListViewAdapter extends BaseAdapter {

    private Context mcontext;
    private List<User_Limit> list_name;
    private List<XYF_JiLu> list_xyf;
    private int mtype;
    public Topic_ListViewAdapter(Context context, List<User_Limit> name, List<XYF_JiLu> list, int type){
        mcontext = context;
        list_name = name;
        list_xyf = list;
        mtype = type;
    }

    @Override
    public int getCount() {
        if (mtype == 1){
            return list_name.size();
        } else if (mtype == 3){
            return list_name.size();
        } else {
            return list_xyf.size();
        }
    }

    @Override
    public Object getItem(int position) {
        if (mtype == 1){
            return list_name.get(position);
        } else if (mtype == 3){
            return list_name.get(position);
        } else {
            return list_xyf.get(position);
        }
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @SuppressLint("SetTextI18n")
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (mtype == 1){
            convertView = View.inflate(mcontext, R.layout.lv_topic_item, null);
            ImageView iv_main_item = convertView.findViewById(R.id.iv_topic_item);
            TextView tv_topic_item_name = convertView.findViewById(R.id.tv_topic_item_name);
            Glide.with(mcontext).load(list_name.get(position).getImage()).apply(new RequestOptions()
                    .placeholder(R.mipmap.banner).error(R.mipmap.banner)
                    .diskCacheStrategy(DiskCacheStrategy.NONE)//关闭Glide的硬盘缓存机制
            ).into(iv_main_item);
            tv_topic_item_name.setText("#" + list_name.get(position).getName());
        } else if (mtype == 3){
            convertView = View.inflate(mcontext, R.layout.gv_publish_add_topic_item, null);
            TextView tv_xyfjilu_name = convertView.findViewById(R.id.tv_xyfjilu_name);
            ImageView iv_publish_icon = convertView.findViewById(R.id.iv_publish_icon);
            Glide.with(mcontext).load(list_name.get(position).getImage()).apply(new RequestOptions()
                            .placeholder(R.mipmap.banner).error(R.mipmap.banner)
                            .diskCacheStrategy(DiskCacheStrategy.NONE)//关闭Glide的硬盘缓存机制
            ).into(iv_publish_icon);
            tv_xyfjilu_name.setText("" + list_name.get(position).getName());
        } else {
            convertView = View.inflate(mcontext, R.layout.square_jilu_lv_item, null);
            Circle_ImageView iv_nearby_item_icon = convertView.findViewById(R.id.iv_nearby_item_icon);
            TextView tv_square_jilu_lv_content = convertView.findViewById(R.id.tv_square_jilu_lv_content);
            TextView tv_nearby_listview_item_name = convertView.findViewById(R.id.tv_nearby_listview_item_name);
            TextView tv_nearby_listview_item_height = convertView.findViewById(R.id.tv_nearby_listview_item_height);
            TextView tv_nearby_listview_item_gxqm = convertView.findViewById(R.id.tv_nearby_listview_item_gxqm);
            ImageView iv_nearby_item_isvip = convertView.findViewById(R.id.iv_nearby_item_isvip);
            ImageView iv_square_jilu_banner = convertView.findViewById(R.id.iv_square_jilu_banner);
            tv_square_jilu_lv_content.setText("" + list_xyf.get(position).getS_content());
            tv_nearby_listview_item_gxqm.setText("" + list_xyf.get(position).getContent());
            tv_nearby_listview_item_name.setText("" + list_xyf.get(position).getNicename());
            if (list_xyf.get(position).getIs_vip().equals("1")){
                iv_nearby_item_isvip.setVisibility(View.VISIBLE);//是 会员
                tv_nearby_listview_item_name.setTextColor(Color.parseColor("#FF3B30"));
            } else {
                iv_nearby_item_isvip.setVisibility(View.GONE);
                tv_nearby_listview_item_name.setTextColor(Color.parseColor("#000000"));
            }
            tv_nearby_listview_item_height.setText("" + list_xyf.get(position).getCreate_at());
            Glide.with(mcontext).load(list_xyf.get(position).getFile()).apply(new RequestOptions()
                    .placeholder(R.mipmap.iv_main_item).error(R.mipmap.iv_main_item)
                    .diskCacheStrategy(DiskCacheStrategy.NONE)//关闭Glide的硬盘缓存机制
            ).into(iv_nearby_item_icon);
            Glide.with(mcontext).load(list_xyf.get(position).getFile()).apply(new RequestOptions()
                    .placeholder(R.mipmap.iv_main_item).error(R.mipmap.iv_main_item)
                    .diskCacheStrategy(DiskCacheStrategy.NONE)//关闭Glide的硬盘缓存机制
            ).into(iv_square_jilu_banner);
        }
        return convertView;
    }
}
